﻿/*---------------------------------------------------------------------------
																PostsSlider widget
																Dependence:jquery.js(1.2.x)|effects.core.js(1.5.2)|widgets.base.js
----------------------------------------------------------------------------*/

var PostsSlider = function() {
	//private area
	var _timerID = null;
	var _slide = function(widget, funBtns, mainBodies) {
		_timerID = setInterval(function() {
			var toShow = $.inArray($("div.btn>a.on", widget)[0], funBtns) + 1;
			if (toShow >= funBtns.length) { toShow = 0; }
			funBtns.removeClass("on").eq(toShow).addClass("on");

			var _effect = UIEffects.random({effects:["fold","slide"]});

			mainBodies.hide().eq(toShow).show(
					_effect.name,
					_effect.dir,
					2000
				);

		}, 5000);
	}; //endof slide

	return {
		init: function(widget) {
			widget = $("#" + widget);
			var mainBodies = $("div.entry", widget);
			var funBtns = $("div.btn>a", widget);
			//periodically slide
			_slide(widget, funBtns, mainBodies);
			//hover effects
			funBtns.hover(
				function() {
					clearInterval(_timerID);
					var _index = $.inArray($(this)[0], funBtns);
					funBtns.removeClass("on").eq(_index).addClass("on");
					mainBodies.hide().eq(_index).show("slow");
				},
				function() {
					$(this).removeClass("on");
					_slide(widget, funBtns, mainBodies);
				}
			);

			//first page load.
			funBtns.eq(0).addClass("on");
			mainBodies.hide().eq(0).show("slow");
		} //endof init
	};
} ();